/*MyPhotoIndex Free Photo Organizer <www.myphotoindex.com>
  Copyright (C) <2006-2009>  <Asaf Yarkoni asaf@yarkoni.net>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
using System;
using System.Collections.Generic;
using System.Text;

namespace MyPhotoIndex
{
    public class ProgressStats
    {
        private DateTime m_startTime;
        private int m_maximum;
        private int m_lastValue;
        private DateTime m_lastValueDateTime;

        public ProgressStats(int maximum)
        {
            m_maximum = maximum;
            m_startTime = DateTime.Now; 
        }

        public void Update(int value)
        {
            m_lastValue = value;
            m_lastValueDateTime = DateTime.Now;
        }

        public TimeSpan EstimatedTimeLeft
        {
            get
            {
                if (m_lastValue == 0 ||
                    m_maximum == 0)
                {
                    return TimeSpan.Zero;
                }

                TimeSpan elapsedTime = m_lastValueDateTime - m_startTime;

                float pace = (float)m_lastValue / (float)elapsedTime.TotalSeconds;
                float processLeft = (float)m_maximum - (float)m_lastValue;

                int secondsLeft = (int)(processLeft / pace);

                TimeSpan timeLeft = new TimeSpan(0, 0, secondsLeft);

                return timeLeft;
            }
        }

 
    }
}
